package res.graph;

import java.util.Collection;
import java.util.LinkedList;

import res.Pair;
import res.Util;

public class EdgeConstraints {
	private final Pair<Integer, Integer> edge;
	private final LinkedList<Pair<Integer, Integer>> allowConstr;
	private final LinkedList<Pair<Integer, Integer>> forbidConstr;
	private final LinkedList<Pair<Integer, Integer>> partners;
	private final LinkedList<Pair<Integer, Integer>> competitors;
	protected final int hash;
	
	public EdgeConstraints(Pair<Integer, Integer> e) {
		if(e == null) throw new NullPointerException();
		
		edge = e;
		allowConstr = new LinkedList<Pair<Integer, Integer>>();
		forbidConstr = new LinkedList<Pair<Integer, Integer>>();
		partners = new LinkedList<Pair<Integer, Integer>>();
		competitors = new LinkedList<Pair<Integer, Integer>>();
		hash = Util.getRandom().nextInt();
	}
	
	public void addAllowed(int v) {
		allowConstr.add(new Pair<Integer, Integer>(edge.getValue2(), v));
	}
	
	public void addForbidden(int v) {
		forbidConstr.add(new Pair<Integer, Integer>(edge.getValue2(), v));
	}
	
	public void addPartner(int v) {
		partners.add(new Pair<Integer, Integer>(v, edge.getValue2()));
	}
	
	public void addCompetitor(int v) {
		competitors.add(new Pair<Integer, Integer>(v, edge.getValue2()));
	}
	
	public Pair<Integer, Integer> getEdge() {
		return edge;
	}
	
	public Collection<Pair<Integer, Integer>> getAllowConstraints() {
		return allowConstr;
	}
	
	public Collection<Pair<Integer, Integer>> getForbidConstraints() {
		return forbidConstr;
	}
	
	public Collection<Pair<Integer, Integer>> getPartners() {
		return partners;
	}
	
	public Collection<Pair<Integer, Integer>> getCompetitors() {
		return competitors;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj != null && obj instanceof EdgeConstraints) {
			EdgeConstraints ec = (EdgeConstraints) obj;
			
			return ec.edge.equals(this.edge)
				&& ec.allowConstr.equals(this.allowConstr)
				&& ec.forbidConstr.equals(this.forbidConstr)
				&& ec.partners.equals(this.partners)
				&& ec.competitors.equals(this.competitors);
		} else
			return false;
	}
	
	@Override
	public int hashCode() {
		return hash;
	}
	
}
